# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

pkgname=ansible-bender
pkgver=0.10.1
pkgrel=2
pkgdesc='Build container images using Ansible playbooks'
arch=('any')
url='https://github.com/ansible-community/ansible-bender'
license=('MIT')
depends=(
  'ansible'
  'ansible-core'
  'podman'
  'buildah'
  'python'
  'python-jsonschema'
  'python-pyyaml'
  'python-setuptools'
  'python-tabulate'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools-scm'
  'python-wheel'
)
checkdepends=(
  'python-flexmock'
  'python-pytest'
)
source=("$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
b2sums=('1bc0347bb1e2f42732dd0afe81a96e8e025132f85850600f8c64dbad4e33fc14527805877cd196bec954f160a2a551f8566dc6a4831f4c8a3e81286acdd98daf')

prepare() {
  cd "$pkgname-$pkgver"

  # drop python-setuptools-scm-git-archive as it is included in
  # python-setuptools-scm >= 7.0.0
  sed -e '/setuptools_scm_git_archive/d' -i setup.cfg
}

build() {
  cd "$pkgname-$pkgver"

  SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver" python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    --ignore tests/integration/
    --ignore tests/functional/
  )

  cd "$pkgname-$pkgver"
  pytest "${pytest_options[@]}"
}

package() {
  cd "$pkgname-$pkgver"

  python -m installer --destdir="$pkgdir" dist/*.whl

  install -vDm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}
